package tsj.ai.alibaba.data.analysis.common.enums;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Optional;

/**
 * @author taoshujian
 * @version 1.0
 * @since 2025-11-14 11:45:45
 */
public enum DbAccessTypeEnum {
    JDBC("jdbc"),

    SDK("sdk"),

    DATA_API("data-api"),

    FC_HTTP("fc-http"),

    MEMORY("in-memory");

    private String code;

    DbAccessTypeEnum(String code) {
        this.code = code;
    }

    public static DbAccessTypeEnum of(String code) {
        if (StringUtils.isBlank(code)) {
            return null;
        }

        Optional<DbAccessTypeEnum> any = Arrays.stream(values())
                .filter(typeEnum -> code.equals(typeEnum.getCode()))
                .findAny();

        return any.orElse(null);
    }

    public String getCode() {
        return code;
    }
}
